package org.eenie.dagger2.injector.modules;

import android.content.Context;

import org.eenie.dagger2.entity.ArticleDao;
import org.eenie.dagger2.entity.DaoMaster;
import org.eenie.dagger2.entity.DaoSession;
import org.eenie.dagger2.entity.DiscussDao;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

/**
 * Created by Eenie on 2017/5/5.
 * Email: eeniework@gmail.com
 * Des:提供数据库存储相关实例
 */
@Module
public class DBModule {

    public static final String DB_NAME = "kdt_db.db";

    @Provides
    @Singleton
    DaoMaster.DevOpenHelper provideDevOpenHelper(Context context) {
        return new DaoMaster.DevOpenHelper(context, DB_NAME);
    }


    @Provides
    @Singleton
    DaoMaster provideDaoMaster(DaoMaster.DevOpenHelper helper) {
        return new DaoMaster(helper.getWritableDatabase());
    }


    @Provides
    @Singleton
    DaoSession provideDaoSession(DaoMaster master) {
        return master.newSession();
    }

    @Provides
    @Singleton
    ArticleDao getArticleDao(DaoSession session) {
        return session.getArticleDao();
    }

    @Provides
    @Singleton
    DiscussDao getDiscussDao(DaoSession session) {
        return session.getDiscussDao();
    }


}
